#include"UnitSR.h"

#include"Field.h"
#include"Map.h"

#include<stdio.h>

#include<QMap>

UnitSR::UnitSR(Map *map, UnitAge age, Team team):Unit(map, team, _getFullName(age), "SR", age){
	_initStats(age);
	m_hasRetaliated = true;
}

UnitSR::~UnitSR(){
	
}

//TODO: This could probably use some tweaking.
///Regardless, this should suffice for now.
double UnitSR::getAttackPriority(const Unit *unit)const{
	double priority = 0;
	priority += (10 - unit->health());
	if(unit->type() == TYPE_HM)
		priority += 10;
	else if(unit->type() != TYPE_FM)
		priority += 5;
	priority += unit->attack(true)/100.0;
	priority -= unit->defense(true)/100.0;
	if(priority <= 0)//Just for safety's sake here...
		priority = .001;
	return priority;
}

int UnitSR::getFieldPriorityForField(Field *field)const{
	if(field->type() == FIELD_ROCKS)
		return 2;
	return 0;
}

QString UnitSR::_getFullName(UnitAge age){
	switch(age){
		case AGE_BRZ:
			return "Slinger";
		case AGE_IRN:
			return "Archer";
		case AGE_EMA:
			return "Mounted Archer";
		case AGE_HMA:
			return "Crossbowman";
		case AGE_LMA:
			return "Longbow Archer";
		case AGE_CA:
			return "Musketeer";
		case AGE_IA:
			return "Rifleman";
		default:
			return "Slinger";
	}
}

void UnitSR::_initStats(UnitAge age){
	switch(age){
		case AGE_BRZ:
			m_attack = 7;
			m_defense = 3;
			m_range = 5;
			m_speed = 12;
			m_attackBonusRocks = 1;
			m_attackBonusHM = 3;
			m_defenseBonusHM = 3;
			break;
		case AGE_IRN:
			m_attack = 11;
			m_defense = 4;
			m_range = 6;
			m_speed = 12;
			m_attackBonusRocks = 2;
			m_attackBonusHM = 4;
			m_defenseBonusHM = 4;
			break;
		case AGE_EMA:
			m_attack = 6;
			m_defense = 5;
			m_range = 5;
			m_speed = 25;
			m_attackBonusRocks = 3;
			m_attackBonusHM = 3;
			m_defenseBonusHM = 3;
			break;
		case AGE_HMA:
			m_attack = 20;
			m_defense = 10;
			m_range = 5;
			m_speed = 12;
			m_attackBonusRocks = 3;
			m_attackBonusHM = 6;
			m_defenseBonusHM = 6;
			break;
		case AGE_LMA:
			m_attack = 24;
			m_defense = 12;
			m_range = 7;
			m_speed = 12;
			m_attackBonusRocks = 4;
			m_attackBonusHM = 7;
			m_defenseBonusHM = 7;
			break;
		case AGE_CA:
			m_attack = 30;
			m_defense = 18;
			m_range = 7;
			m_speed = 12;
			m_attackBonusRocks = 6;
			m_attackBonusHM = 10;
			m_defenseBonusHM = 10;
			break;
		case AGE_IA:
			m_attack = 28;
			m_defense = 25;
			m_range = 8;
			m_speed = 12;
			m_attackBonusRocks = 9;
			m_attackBonusHM = 15;
			m_defenseBonusHM = 15;
			break;
	}
}

int UnitSR::attackTerrainBonus()const{
	if(field()->type() == FIELD_ROCKS)
		return m_attackBonusRocks;
	return 0;
}

int UnitSR::defenseBonusAgainst(UnitType type)const{
	if(type == TYPE_HM)
		return m_defenseBonusHM;
	return 0;
}

int UnitSR::attackBonusAgainst(UnitType type)const{
	int bonus = 0;
	if(field()->type() == FIELD_ROCKS)
		bonus += m_attackBonusRocks;
	if(type == TYPE_HM)
		bonus += m_attackBonusHM;
	return bonus;
}

/*	switch(age){
		case AGE_BRZ:
			break;
		case AGE_IRN:
			break;
		case AGE_EMA:
			break;
		case AGE_HMA:
			break;
		case AGE_LMA:
			break;
		case AGE_CA:
			break;
		case AGE_IA:
			break;
		default:
			break;
	}*/ 
 
